<!DOCTYPE html>
<html lang="zh-cn"><head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/main.css" rel="stylesheet">

    <link rel="shortcut icon" type="image/x-icon" href="/img/favicon.ico" />

    <title>caddy的配置文件 | wiseAI的小站</title>
</head><body><div class="container-fluid">
    <nav class="navbar fixed-top navbar-expand-sm navbar-dark bg-dark">
        <div class="container-fluid">
            <a class="navbar-brand" href="/">
                <img src="/img/favicon.ico" alt="" width="30" height="24" class="d-inline-block align-text-top">
                wiseAI的小站
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/articles/">文章</a>
                    </li>
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/categories/">分类</a>
                    </li>
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/tags/">关键字</a>
                    </li>
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/post/golang/">golang编程</a>
                    </li>
                    
                    <li class="nav-item">
                        <a  class="nav-link"   href="/about/">关于</a>
                    </li>
                    
                </ul>
                <form class="d-flex">
                    <input id="search-query" class="form-control me-2" type="search" placeholder="Search for anything..." aria-label="Search">
                </form>
            </div>
        </div>
    </nav>
</div>




<div id="content">
<div class="container article">
	<h1>caddy的配置文件</h1>
	<div class="post-meta">
		<div>
			
			
			By wiseai | 2023-03-22 | 1 minutes
		</div>
		<div class="tags">
			
			<a class="btn btn-light links btn-sm" href="/tags/http%E6%9C%8D%E5%8A%A1%E5%99%A8/">http服务器</a>
			
		</div>
	</div>
	<div>
		<div class="article-post">
			<ul>
<li>安装
首先安装xcaddy，这个是可以编译带扩展的程序，具体的看源码说明。</li>
</ul>
<pre tabindex="0"><code># go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
</code></pre><p>再使用xcaddy编译caddy程序</p>
<pre tabindex="0"><code>$ xcaddy build [&lt;caddy_version&gt;]
    [--output &lt;file&gt;]
    [--with &lt;module[@version][=replacement]&gt;...]
</code></pre><ul>
<li>下面的是一个示例文件，是<a href="https://r2wind.cn/articles/20220412.html">“小泽”的文章</a>，很不错。</li>
</ul>
<pre tabindex="0"><code>// 此处的配置是用来支持HTTP3的,若不需要删除即可
{
	servers {
		protocol {
			experimental_http3
		}
	}
}
// 一个普通的网站示例，r2wind.com替换成你喜欢的域名
r2wind.com {
  // 此处配置网站根目录，请将页面文件上传至网站根目录
	root * /www/wwwroot/r2wind.com/public
  // 配置SSL证书路径，若不配置，Caddy会帮你自动申请并配上
	tls /etc/ssl/caddy/r2wind.cn.crt /etc/ssl/caddy/r2wind.cn.key
  // 自定义错误页文件，若不需要删除即可
	handle_errors {
		rewrite * /{http.error.status_code}.html
		file_server
	}
  // 日志保存路径，如不需要保存访问日志可删除
	log {
		output file /www/log/r2wind_com.log
	}
  // 开启Gzip压缩，若不需要可删除
	encode gzip
	file_server
  // 用来添加响应头
	header {
    // 禁用了客户端的 MIME 类型嗅探行为，若不需要请删除
		X-content-type-tptions nosniff
    // 拒绝嵌入其他网站，若不需要请删除
		X-frame-options DENY
    // HSTS响应头，若不需要请删除
		Strict-Transport-Security max-age=63072000;includeSubDomains;preload
	}
}
// 一个反向代理示意配置
yjz.hk {
  // 指定代理网页访问地址https://xx.r2w.dev
	reverse_proxy https://xx.r2w.dev {
    // 指定请求域名hk.r2w.dev
		header_up Host {hk.r2w.dev}
	}
  // 下面的配置在上面已经介绍过了，这里不再过多赘述
	tls /etc/ssl/caddy/r2wind.cn.crt /etc/ssl/caddy/r2wind.cn.key
	handle_errors {
		rewrite * /{http.error.status_code}.html
		file_server
	}
	log {
		output file /www/log/yjz_hk.log
	}
	encode gzip
	file_server
	header {
		X-content-type-tptions nosniff
		x-xss-protection: 1; mode=block
		Strict-Transport-Security max-age=63072000;includeSubDomains;preload
	}
}
// 一个重定向示例配置
www.yjz.hk {
  // 指定重定向后的网站地址并携带相关参数
	redir https://yjz.hk{uri}
}
// 一个多域名重定向示例配置，多个域名记得用&#34;,&#34;隔开，逗号后记得先打空格再输入域名
dnstest.cc, www.dnstest.cc, r2wind.net, www.r2wind.net {
	redir https://r2wind.cn
}
// 一个多域名网站示例配置，和普通网站配置一样，只不过多了几个域名
r2wind.com，r2wind.net, r2wind.cn {
  // 此处配置网站根目录，请将页面文件上传至网站根目录
	root * /www/wwwroot/r2wind.com/public
  // 配置SSL证书路径，若不配置，Caddy会帮你自动申请并配上,注意：此处最好不要指定SSL证书，除非你的证书是多域名的
	tls /etc/ssl/caddy/r2wind.cn.crt /etc/ssl/caddy/r2wind.cn.key
  // 自定义错误页文件，若不需要删除即可
	handle_errors {
		rewrite * /{http.error.status_code}.html
		file_server
	}
  // 日志保存路径，如不需要保存访问日志可删除
	log {
		output file /www/log/r2wind_com.log
	}
  // 开启Gzip压缩，若不需要可删除
	encode gzip
	file_server
  // 用来添加响应头
	header {
    // 禁用了客户端的 MIME 类型嗅探行为，若不需要请删除
		X-content-type-tptions nosniff
    // 拒绝嵌入其他网站，若不需要请删除
		X-frame-options DENY
    // HSTS响应头，若不需要请删除
		Strict-Transport-Security max-age=63072000;includeSubDomains;preload
	}
}
</code></pre>
		</div>
	</div>
</div>


<div class="container">
    
    <div class="row">
        
        <div class="col-5">
            <a class="page-link link-dark text-end dh" href="/post/2023.03.20-linux%E5%91%BD%E4%BB%A4dd/">
                <h5>前一篇</h5><br>
                dd命令
            </a>            
        </div>
        
        <div class="col-2">
        </div>
        
        <div class="col-5">
            <a class="page-link link-dark text-start dh" href="">
                <h5>没有了</h5><br>
            </a>            
        </div>
        
    </div>
    
</div>

        </div><br><br>
<footer class="container">
    <h2>友情链接</h2>
    <hr>
    <nav class="nav nav-pills flex-column flex-sm-row">
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/gnzg/index.html" target="_blank">孤鸟之歌</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/mm/index.html" target="_blank">生成随机字符</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/md/index.html" target="_blank">MarkDown</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://gitee.com/" target="_blank">Gitee</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://github.com/" target="_blank">Github</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.aliyun.com/" target="_blank">阿里云</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://cloud.tencent.com/" target="_blank">腾讯云</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.oschina.net/" target="_blank">OSCHINA开源中国</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://gitee.com/wiseai/the-way-to-go_ZH_CN/blob/master/eBook/directory.md" target="_blank">the way to go</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://topgoer.com/" target="_blank">golang文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://goframe.org/display/gf" target="_blank">GoFrame</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.aliyundrive.com/" target="_blank">阿里云盘</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://cn.vuejs.org/" target="_blank">vue3文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://element-plus.gitee.io/zh-CN/" target="_blank">element-plus文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.runoob.com/vue3/vue3-tutorial.html" target="_blank">vue3菜鸟教程</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://v5.bootcss.com/" target="_blank">bootstrap v5 中文文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.bootstrap.cn/" target="_blank">bootstrap文档</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://caddy2.dengxiaolong.com/docs/" target="_blank">caddy中文教程</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.58pic.com/" target="_blank">千图</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://ifonts.com/" target="_blank">iFonts</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://marketing.qiniu.com/" target="_blank">七牛云</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.ixigua.com/" target="_blank">西瓜视频</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/yugang/index.html" target="_blank">鱼缸计算</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://justcc.mengkang.net/#/" target="_blank">C语言JustCC</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://wiseai.gitee.io/pages/pptist/" target="_blank">PPTist</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="/index.xml" target="_blank">RSS</a>
        
        <a class="flex-sm-fill text-sm-center nav-link links link-dark" href="https://www.kancloud.cn/idcpj/python/418553" target="_blank">参考资料</a>
        
    </nav>

    <div class="copyright text-center">
      <span class="power-by">
        Powered by <a class="links" href="https://gohugo.io" target="_blank">Hugo</a>
    </span>
    <span>|</span>
    <span>
        Theme - <a class="links" href="https://github.com/wiseai-go/blog-hugo" target="_blank">WiseAI</a>
    </span>
    <br>
    <span class="copyright-year">
        &copy;
        
        2017 -
        2023<span>
            陇ICP备15000157号
            
        </span></span>

</div>
</footer>
<script src="/js/bootstrap.bundle.min.js"></script>


</body>
</html>
